import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

class CircularCachedNetworkImage extends StatelessWidget {
  final String url;
  final double width;
  final double height;
  final BoxFit? fit;
  final double? radius;

  const CircularCachedNetworkImage({
    super.key,
    required this.url,
    required this.width,
    required this.height,
    this.fit,
    this.radius,
  });

  @override
  Widget build(BuildContext context) {
    // String urlStr = StringUtil.supportCdnUrl(url: url,width: width) ??'';
    return ClipRRect(
        borderRadius: BorderRadius.circular(radius ?? 4),
        child: CachedNetworkImage(
          imageUrl: url,
          imageBuilder: (context, imageProvider) => Container(
            height: height,
            width: width,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: imageProvider,
                fit: fit ?? BoxFit.cover,
              ),
            ),
          ),
          placeholder: (context, url) => Container(
            height: height,
            width: width,
            color: Colors.grey,
            child: const Center(
              child: CircleAvatar(
                backgroundColor: Colors.grey,
              ),
            ),
          ),
          errorWidget: (context, url, error) => Container(
            height: height,
            width: width,
            color: Colors.grey,
            child: const Center(
              child: CircleAvatar(
                backgroundColor: Colors.grey,
              ),
            ),
          ),
        ));
  }
}
